package srcBlackJack;

public class BlackJackState 
{
    int pMinSum;
    int dMinSum;
    
    // pairValue being non-zero means, 
    // player has exactly 2 cards, which is a pair of value contained in pairValue
    int pairValue;
    
    boolean pHasAce;
    boolean dHasAce;
    boolean pHasBlackJack;
    boolean dHasBlackJack;
    boolean pTurn;
    boolean isTerminalState;
    boolean pHasTwoCards;
    boolean dHasOnlyAceCard;
    boolean dHasOnlyFaceCard;

    public BlackJackState(
            int pMinSum,
            int dMinSum,
            int pairValue,
            boolean pHasAce,
            boolean dHasAce,
            boolean pHasBlackJack,
            boolean dHasBlackJack,
            boolean pTurn,
            boolean isTerminalState,
            boolean pHasTwoCards,
            boolean dHasOnlyAceCard,
            boolean dHasOnlyFaceCard) 
    {
        this.pMinSum = pMinSum;
        this.dMinSum = dMinSum;
        this.pairValue = pairValue;
        this.pHasAce = pHasAce;
        this.dHasAce = dHasAce;
        this.pHasBlackJack = pHasBlackJack;
        this.dHasBlackJack = dHasBlackJack;
        this.pTurn = pTurn;
        this.isTerminalState = isTerminalState;
        this.pHasTwoCards = pHasTwoCards;
        this.dHasOnlyAceCard = dHasOnlyAceCard;
        this.dHasOnlyFaceCard = dHasOnlyFaceCard;
    }

    public boolean DHasAce() {
        return dHasAce;
    }

    public boolean DHasBlackJack() {
        return dHasBlackJack;
    }
    
    public boolean DHasOnlyAceCard() {
        return dHasOnlyAceCard;
    }

    public boolean DHasOnlyFaceCard() {
        return dHasOnlyFaceCard;
    }

    public int DMinSum() {
        return dMinSum;
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj)
            return true;
        if (obj == null)
            return false;
        if (getClass() != obj.getClass())
            return false;
        BlackJackState other = (BlackJackState) obj;
        if (dHasAce != other.dHasAce)
            return false;
        if (dHasBlackJack != other.dHasBlackJack)
            return false;
        if (dHasOnlyAceCard != other.dHasOnlyAceCard)
            return false;
        if (dHasOnlyFaceCard != other.dHasOnlyFaceCard)
            return false;
        if (dMinSum != other.dMinSum)
            return false;
        if (isTerminalState != other.isTerminalState)
            return false;
        if (pHasAce != other.pHasAce)
            return false;
        if (pHasBlackJack != other.pHasBlackJack)
            return false;
        if (pHasTwoCards != other.pHasTwoCards)
            return false;
        if (pMinSum != other.pMinSum)
            return false;
        if (pTurn != other.pTurn)
            return false;
        if (pairValue != other.pairValue)
            return false;
        return true;
    }

    @Override
    public int hashCode() {
        final int prime = 31;
        int result = 1;
        result = prime * result + (dHasAce ? 1231 : 1237);
        result = prime * result + (dHasBlackJack ? 1231 : 1237);
        result = prime * result + (dHasOnlyAceCard ? 1231 : 1237);
        result = prime * result + (dHasOnlyFaceCard ? 1231 : 1237);
        result = prime * result + dMinSum;
        result = prime * result + (isTerminalState ? 1231 : 1237);
        result = prime * result + (pHasAce ? 1231 : 1237);
        result = prime * result + (pHasBlackJack ? 1231 : 1237);
        result = prime * result + (pHasTwoCards ? 1231 : 1237);
        result = prime * result + pMinSum;
        result = prime * result + (pTurn ? 1231 : 1237);
        result = prime * result + pairValue;
        return result;
    }

    public boolean IsTerminalState() 
    {
        return isTerminalState;
    }
    
    public int PairValue() {
        return pairValue;
    }

    public boolean PHasAce() {
        return pHasAce;
    }

    public boolean PHasBlackJack() {
        return pHasBlackJack;
    }

    public boolean PHasTwoCards() {
        return pHasTwoCards;
    }

    public int PMinSum() {
        return pMinSum;
    }

    public boolean PTurn() {
        return pTurn;
    }

    @Override
    public String toString() {
        return String
                .format("BlackJackState [pMinSum=%s, dMinSum=%s, pairValue=%s, pHasAce=%s, dHasAce=%s, pHasBlackJack=%s, dHasBlackJack=%s, pTurn=%s, isTerminalState=%s, pHasTwoCards=%s, dHasOnlyAceCard=%s, dHasOnlyFaceCard=%s]",
                        pMinSum, dMinSum, pairValue, pHasAce, dHasAce,
                        pHasBlackJack, dHasBlackJack, pTurn, isTerminalState,
                        pHasTwoCards, dHasOnlyAceCard, dHasOnlyFaceCard);
    }
}
